<div class="archive">
<?php 
if ( have_posts() ) : ?>
<?php  while ( have_posts() ) : the_post();?>

<div class="hentry-meta"><h1><?php the_title(); ?></h1></div>
<section class="general-wrapper product">
<!--<article class="product-detail">
<?php if ( has_post_thumbnail() ) the_post_thumbnail('post-detail'); ?>
<?php the_content()?>
<div class="clearfix"></div><!-- Just to increase height automatically
</article>-->
<?php endwhile?>

<!-- feature slider -->
<?php

$topListed = get_post_meta($post->ID, 'top_listed');
$arrTopPosts = array();
$postIDs = array();
foreach($topListed as $tl)
{
	$breakAPart = explode(',',$tl);
	$arrTopPosts[$breakAPart[0]] = $breakAPart[1];
	$postIDs[] = $breakAPart[0];
}


            $args = array(
                'post__in'=> $postIDs
            );
            query_posts($args);
            if ( have_posts() ) :
		
        ?>
        <div id="mainposts">
            <ul>
                <?php while (have_posts() ) : the_post(); 
			
				$mainImage = $arrTopPosts[get_the_ID()];		//get_post_meta(get_the_ID(), 'top_image_url', true);
				?>
                <li>
                    <div class="mainpost">
                        <?php //if ( has_post_thumbnail() ) the_post_thumbnail('slide-magazine'); ?>
                        <img width="620" height="365" title="<?php the_title(); ?>" alt="<?php the_title(); ?>" class="attachment-slide-magazine wp-post-image" src="<?php echo trim($mainImage)?>">
                        <div class="mainpost-container">
                            <div class="bg"></div>
                            <div class="mainpost-data">
                                <!--<div class="mainpost-meta"><?php echo get_the_date(); ?> &middot; <?php comments_popup_link ( __('0 Comments', 'unspoken'), __('1 Comment', 'unspoken'), __('% Comments', 'unspoken'), '', __('Comments off', 'unspoken')); ?> &middot; <?php the_category(', '); ?></div>-->
                                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                <?php the_excerpt(); ?>
                            </div>
                        </div>
                    </div>
                </li>
                <?php
                    endwhile;
                    wp_reset_query();
                ?>
            </ul>
            <a href="javascript: void(0);" class="prev"></a>
            <a href="javascript: void(0);" class="next"></a>
        </div>
        <?php endif; ?>
        <div class="clearfix"></div>
                
<!-- feature slider ends -->        


<?php

$productCompany = get_post_meta($post->ID, 'product_companies', true);
$arrCompanies = explode(',', $productCompany);

/*$args = array(
             'post__in'=> $arrCompanies,  //getting compaines list
			 'orderby' => 'none'
            );

            query_posts($args);
            if ( have_posts() ) :*/
			
$args = array (
    'posts_per_page' => -1,
    'post__in' => $arrCompanies,
    'orderby' => 'none'
);

$query = new WP_Query ( $args );

$ordered_posts = array();
foreach($arrCompanies as $rpid)
 foreach($query->posts as $index => $fpid)
 {
   if($fpid->ID == $rpid) 
   {
	   $ordered_posts[] = $query->posts[$index];
	   //print_r($ordered_posts);
   }
 }
   //echo 'fpid '.$index;

$query->posts = $ordered_posts;

?>
<ul class="company-listings">
<?php while ($query->have_posts() ) : $query->the_post();?>
	<li>
    	<section class="company-logo">
    		<!--<img src="<?php bloginfo('template_directory')?>/images/product-page-logo.jpg" alt="Company Logo" />-->
            <?php if ( has_post_thumbnail() ): 
					the_post_thumbnail('company-logo');
				else:
				?>
             <img src="<?php bloginfo('template_directory')?>/images/noLogo.png" alt="<?php the_title()?>" />
             <?php endif;?>
    	</section>
        <section class="company-detail">
        	<!--Premium Listings-->
            <div class="title"><?php the_title()?></div>
            <p><?php the_excerpt()?></p>
        </section>
        <section class="company-contact">
        	<!--Creastone Limited-->
            <a href="<?php the_permalink()?>"><input type="button" value="Contact Seller" /></a>
        </section>
        <div class="clearfix"></div><!-- Just to increase height automatically -->
    </li>
<?php
endwhile;
wp_reset_query();
endif;
?>
	
</ul>

</section>

</div>
